package com.qipay.baas.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.qipay.baas.model.CpInfo;

public class CpInfoSqlProvider {

    public String insertSelective(CpInfo record) {
        BEGIN();
        INSERT_INTO("cp_info");
        
        if (record.getCpId() != null) {
            VALUES("cp_id", "#{cpId,jdbcType=BIGINT}");
        }
        
        if (record.getName() != null) {
            VALUES("`name`", "#{name,jdbcType=VARCHAR}");
        }
        
        if (record.getLegalPerson() != null) {
            VALUES("legal_person", "#{legalPerson,jdbcType=VARCHAR}");
        }
        
        if (record.getLegalPersonIdcard1() != null) {
            VALUES("legal_person_idcard1", "#{legalPersonIdcard1,jdbcType=VARCHAR}");
        }
        
        if (record.getLegalPersonIdcard2() != null) {
            VALUES("legal_person_idcard2", "#{legalPersonIdcard2,jdbcType=VARCHAR}");
        }
        
        if (record.getBusinessLicenseNo() != null) {
            VALUES("business_license_no", "#{businessLicenseNo,jdbcType=VARCHAR}");
        }
        
        if (record.getBusinessLicensePic() != null) {
            VALUES("business_license_pic", "#{businessLicensePic,jdbcType=VARCHAR}");
        }
        
        if (record.getOrgCodeLicense() != null) {
            VALUES("org_code_license", "#{orgCodeLicense,jdbcType=VARCHAR}");
        }
        
        if (record.getMail() != null) {
            VALUES("mail", "#{mail,jdbcType=VARCHAR}");
        }
        
        if (record.getAddr() != null) {
            VALUES("addr", "#{addr,jdbcType=VARCHAR}");
        }
        
        if (record.getUrl() != null) {
            VALUES("url", "#{url,jdbcType=VARCHAR}");
        }
        
        if (record.getIndustry() != null) {
            VALUES("industry", "#{industry,jdbcType=VARCHAR}");
        }
        
        if (record.getContacts() != null) {
            VALUES("contacts", "#{contacts,jdbcType=VARCHAR}");
        }
        
        if (record.getContactsTel() != null) {
            VALUES("contacts_tel", "#{contactsTel,jdbcType=VARCHAR}");
        }
        
        if (record.getContactsMobile() != null) {
            VALUES("contacts_mobile", "#{contactsMobile,jdbcType=VARCHAR}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(CpInfo record) {
        BEGIN();
        UPDATE("cp_info");
        
        if (record.getName() != null) {
            SET("`name` = #{name,jdbcType=VARCHAR}");
        }
        
        if (record.getLegalPerson() != null) {
            SET("legal_person = #{legalPerson,jdbcType=VARCHAR}");
        }
        
        if (record.getLegalPersonIdcard1() != null) {
            SET("legal_person_idcard1 = #{legalPersonIdcard1,jdbcType=VARCHAR}");
        }
        
        if (record.getLegalPersonIdcard2() != null) {
            SET("legal_person_idcard2 = #{legalPersonIdcard2,jdbcType=VARCHAR}");
        }
        
        if (record.getBusinessLicenseNo() != null) {
            SET("business_license_no = #{businessLicenseNo,jdbcType=VARCHAR}");
        }
        
        if (record.getBusinessLicensePic() != null) {
            SET("business_license_pic = #{businessLicensePic,jdbcType=VARCHAR}");
        }
        
        if (record.getOrgCodeLicense() != null) {
            SET("org_code_license = #{orgCodeLicense,jdbcType=VARCHAR}");
        }
        
        if (record.getMail() != null) {
            SET("mail = #{mail,jdbcType=VARCHAR}");
        }
        
        if (record.getAddr() != null) {
            SET("addr = #{addr,jdbcType=VARCHAR}");
        }
        
        if (record.getUrl() != null) {
            SET("url = #{url,jdbcType=VARCHAR}");
        }
        
        if (record.getIndustry() != null) {
            SET("industry = #{industry,jdbcType=VARCHAR}");
        }
        
        if (record.getContacts() != null) {
            SET("contacts = #{contacts,jdbcType=VARCHAR}");
        }
        
        if (record.getContactsTel() != null) {
            SET("contacts_tel = #{contactsTel,jdbcType=VARCHAR}");
        }
        
        if (record.getContactsMobile() != null) {
            SET("contacts_mobile = #{contactsMobile,jdbcType=VARCHAR}");
        }
        
        WHERE("cp_id = #{cpId,jdbcType=BIGINT}");
        
        return SQL();
    }
}